import resquest from '../utils/axios'

// 获取表列表
/**
 * 数据库列表
 * @param params
 */
export const getTableListAPI = (params) => {
    return resquest.get({
        url: '/gen/tableList',
        params
    })
}
/**
 * xxTable列表
 * @param params
 */
export const getXXTableListAPI = (params) => {
    return resquest.get({
        url: '/gen/xxTableList',
        params
    })
}
/**
 * xxColumn列表
 * @param params
 */
export const getXXColumnListAPI = (params) => {
    return resquest.get({
        url: '/gen/xxColumnList',
        params
    })
}

// 保存表配置
/**
 * 添加xxTable
 * @param data
 */
export const saveXXTableAPI = (data: any) => {
    return resquest.post({
        url: '/gen/saveXXTable',
        data
    })
}
/**
 * 更新XXColumn
 * @param data
 */
export const updateXXColumnAPI = (data: any) => {
    return resquest.post({
        url: '/gen/updateXXColumn',
        data
    })
}
/**
 * 下载代码
 */
export const downloadFileAPI = (params) => {
    return resquest.get({
        url: `/gen/generate`,
        params,
        responseType: 'blob'
    })
}

export function exportExcel(res: any, xlsName: any, fileExtension?: string) {
    const url = window.URL.createObjectURL(new Blob([res]))
    const link = document.createElement('a')
    link.href = url
    link.setAttribute('download', `${xlsName}.${fileExtension}`)
    document.body.appendChild(link)
    link.click()
    link.remove()
    window.URL.revokeObjectURL(url)
    window.$message.success('导出成功', { duration: 5000 })
}